﻿Imports System.Collections.Generic
Imports System.Data
Imports Sistema_InformacionNaviera.BC
Imports Sistema_InformacionNaviera.BE
Imports Sistema_InformacionNavier.UTIL
Imports System.Xml

Public Class BuscarContenedor

    Inherits System.Web.UI.Page
    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
        If Not Page.IsPostBack Then
            ListarContendores()
        End If
    End Sub

    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarContendores()
    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub

    Private Sub ListarContendores()

        Dim objBLImpoBE As New BillOfLadingImpoBE
        Dim objUtil As New Funciones
        If txtPrefijo.Text.Trim <> "" Then
            objBLImpoBE.Bec_Pref = objUtil.ReemplazarTexto(txtPrefijo.Text.Trim)
        Else
            objBLImpoBE.Bec_Pref = ""
        End If

        Dim bExito As Boolean
        Dim sMensaje As String = String.Empty
        Dim dt As DataTable = Nothing

        objBLImpoBE.KBLM = Session("CodigBL")
        objBLImpoBE.KVJE = Session("CodigVje")

        Dim objContenedor As New BillOfLadingImpoBC

        objContenedor.ObtieneBlImpoContenedor(objBLImpoBE, dt, bExito, sMensaje)
        dgContenedor.DataSource = dt
        dgContenedor.DataBind()

        If dgContenedor.Rows.Count <= 0 Then
            dgContenedor.Visible = False
            lblError.Visible = True
        Else
            dgContenedor.Visible = True
            lblError.Visible = False
        End If
    End Sub




    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click
        Dim dt As New DataTable
        Dim sContPrefijo As String = String.Empty
        Dim sContNumero As String = String.Empty
        Dim sContPesoBruto As String = String.Empty
        Dim scadena As String
        Dim sContenedores As String = String.Empty

        For Each Me.itemgridview In dgContenedor.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                sContPrefijo = CType(itemgridview.FindControl("lblcodigo"), Label).Text
                sContNumero = CType(itemgridview.FindControl("lblDescripcion"), Label).Text
                sContPesoBruto = CType(itemgridview.FindControl("lblPesoBruto"), Label).Text


            End If

            'sContenedores = sContenedores + " / " + sContPrefijo & "-" & sContNumero
            sContenedores = sContPrefijo & "-" & sContNumero

        Next



        'sContenedores = sContenedores.Substring(2)

        scadena = sContNumero
        If sContNumero.ToString.Trim = "" Then
            Session("BLCONT_Numero") = ""
            Session("BLCONT_Prefijo") = ""
            Session("BLCONT_Cadena") = ""
            Exit Sub
        End If
        '  Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BLCONT_Prefijo") = sContPrefijo
        Session("BLCONT_Numero") = sContNumero
        Session("BLCONT_Cadena") = sContenedores
        Session("BLCONT_PesoBruto") = sContPesoBruto

    End Sub


    Sub Cambiarpagina(ByVal sender As Object, ByVal e As GridViewPageEventArgs)


        Dim objPuertoBE As New PuertosBE
        Dim objUtil As New Funciones
        If txtPrefijo.Text.Trim <> "" Then
            objPuertoBE.Descripcion = objUtil.ReemplazarTexto(txtPrefijo.Text.Trim)
        Else
            objPuertoBE.Descripcion = ""
        End If

        Dim objPuerto As New PuertosBC
        dgContenedor.PageIndex = e.NewPageIndex
        dgContenedor.DataSource = objPuerto.ListaPuertos(objPuertoBE)
        dgContenedor.DataBind()
        If dgContenedor.Rows.Count <= 0 Then
            dgContenedor.Visible = False
            lblError.Visible = True
        Else
            dgContenedor.Visible = True
            lblError.Visible = False
        End If


    End Sub

    'Protected Sub CheckHeader_OnCheckedChanged(ByVal sender As Object, ByVal e As EventArgs)

    '    Dim i As Integer

    '    If dgContenedor.Rows.Count > 0 Then
    '        Do While i < dgContenedor.Rows.Count
    '            Dim dRow As DataRow = dgContenedor.NewRow

    '            chec()
    '            CheckBox1.CheckBox = True
    '            i = i + 1
    '        Loop
    '    End If



    '      for (int i = 0; i < dgContenedor.Rows.Count; i++)
    '      {
    '        CheckBox cb =dgContenedor.Rows[i].FindControl("CheckBox1");
    '        cb.Checked = true;
    '      }
    'End Sub
End Class